package com.axt.manager.bean;

import com.axt.soa.bean.*;
import com.axt.soa.msg.types.MsgParam;
import com.axt.manager.base.*;
import com.axt.manager.model.*;
import java.util.*;

public class UserBean extends BaseFuncBean {
	/**
	 * 添加用户
	 */
	public int addUser(
			String userName, String personName, String department, 
			String position, String email, String telephone, String passwd) {
		prepare();
		request.addParam(MsgParam.PARA_USER_NAME, passwd);
		request.addParam(MsgParam.PARA_PERSON_NAME, personName);
		request.addParam(MsgParam.PARA_DEPARTMENT, department);
		request.addParam(MsgParam.PARA_POSITION, position);
		request.addParam(MsgParam.PARA_EMAIL, email);
		request.addParam(MsgParam.PARA_TELEPHONE, telephone);
		request.addParam(MsgParam.PARA_PASSWD, passwd);

		if (-1 == execute(MsgFuncExt.FUNC_ADD_USER, CONN_T_TCP)) {
			return -1;
		}
		
		return reply.getParam(MsgParam.PARA_USER_ID).toInteger();
	}

	/**
	 * 获取用户列表
	 */
	public List<User> queryUserList() {
		prepare();
		
		return fetch(MsgFuncExt.FUNC_QUERY_USER, 
				"com.axt.manager.model.User", MsgParam.PARA_USER_LIST, CONN_T_TCP);
	}
	
	/**
	 * 获取用户的角色
	 * @return
	 */
    public String queryUserRole(String userId, String serverId)
    {
		prepare();
		request.addParam(MsgParam.PARA_USER_ID, userId);
		request.addParam(MsgParam.PARA_SVR_ID, serverId);

		execute(MsgFuncExt.FUNC_GET_USER_ROLE, CONN_T_TCP);
		
		return reply.getParam(MsgParam.PARA_ROLE_ID).toString();
    }
    
	/**
	 * 通过用户的ID，删除用户
	 */
	public int deleteUser(String userId) {
		prepare();
		request.addParam(MsgParam.PARA_TG_USER_ID, userId);

		return execute(MsgFuncExt.FUNC_DELETE_USER, CONN_T_TCP);
	}
	
    /**
     * 修改用户信息
     */
	public int modifyUser(
			String userId, String userName, String personName, String department, 
			String position, String email, String telephone, String passwd) {
		prepare();
		request.addParam(MsgParam.PARA_TG_USER_ID, userId);
		//request.addParam(MsgParam.PARA_USER_STATUS, status);
		request.addParam(MsgParam.PARA_USER_NAME, userName);
		request.addParam(MsgParam.PARA_PERSON_NAME, personName);
		request.addParam(MsgParam.PARA_DEPARTMENT, department);
		request.addParam(MsgParam.PARA_POSITION, position);
		request.addParam(MsgParam.PARA_EMAIL, email);
		request.addParam(MsgParam.PARA_TELEPHONE, telephone);
		//request.addParam(MsgParam.PARA_OLD_PASSWD, oldPasswd);
		request.addParam(MsgParam.PARA_PASSWD, passwd);
		
		return execute(MsgFuncExt.FUNC_MODIFY_USER, CONN_T_TCP);
	}
	/**
	 * 锁定用户
	 */
	public int lockUser(String userName) {
		prepare();
		request.addParam(MsgParam.PARA_USER_NAME, userName);

		return execute(MsgFuncExt.FUNC_LOCK_USER, CONN_T_TCP);

	} 
	/**
	 * 解除锁定用户
	 */
	public int unlockUser(String userName) {
		prepare();
		request.addParam(MsgParam.PARA_USER_NAME, userName);

		return execute(MsgFuncExt.FUNC_UNLOCK_USER, CONN_T_TCP);

	} 
	/**
	 * 修改用户密码
	 */
	public int modifyPwd(String userName, String userPwd, String oldPwd) {
		prepare();
		request.addParam(MsgParam.PARA_USER_NAME, userName);
		request.addParam(MsgParam.PARA_PASSWD, userPwd);
		request.addParam(MsgParam.PARA_OLD_PASSWD, oldPwd);

		return execute(MsgFuncExt.FUNC_UNLOCK_USER, CONN_T_TCP);

	} 
}
